import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Layout1 from '@/layout1'
// import Screenlayout from '@/screenLayout'
// import SecondLayout from '@/views/secondLayout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * constantRoutes
 */
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
var constantRoutes1 = [
    // {
    //     path: '/demo',
    //     component: Layout,
    //     meta: { title: "DEMO", icon: 'example' },
    //     redirect: '/listDemo',
    //     children: [{
    //         path: '/demo/listDemo',
    //         component: () =>
    //             import ('@/views/demo/listDemo'),
    //         name: 'ListDemo',
    //         meta: { title: '列表', }
    //     }, {
    //         path: '/demo/cardDemo',
    //         component: () =>
    //             import ('@/views/demo/cardDemo'),
    //         name: 'CardDemo',
    //         meta: { title: '卡片', }
    //     }, {
    //         path: '/demo/detailDemo',
    //         component: () =>
    //             import ('@/views/demo/detailDemo'),
    //         name: 'detailDemo',
    //         meta: { title: '详情', tools: true }
    //     }, {
    //         path: '/demo/dialog',
    //         component: () =>
    //             import ('@/views/demo/treeTableDemo'),
    //         name: 'TreeTableDemo',
    //         meta: { title: '弹出框' }
    //     }]
    // },
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [{
            path: '/redirect/:path(.*)',
            component: () =>
                import('@/views/redirect/index')
        }]
    },
    {
        path: '/login',
        component: () =>
            import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () =>
            import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () =>
            import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () =>
            import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        hidden: true,
        children: [{
            path: '/dashboard',
            component: () =>
                import('@/views/dashboard/index'),
            name: 'Dashboard',
            meta: { title: "主页", icon: 'star', affix: true }
        }, {
            path: '/caseDetail',
            component: () =>
                import('@/views/caseDetail/caseDetail'),
            name: 'CaseDetail',
            hidden: true,
            meta: { title: '案件详情', tools: false }
        }]
    },

    // {
    //     path: '/mainInformation',
    //     component: Layout,
    //     redirect: '/mainInformation',
    //     meta: { title: "主体信息管理", icon: 'star', affix: true },
    //     children: [{
    //         path: '/mainInformation/supervisedObjects',
    //         component: () =>
    //             import('@/views/mainInformation/supervisedObjects'),
    //         name: 'mainInformationSupervisedObjects',
    //         meta: { title: "监管对象管理" }
    //     },]
    // }, {
    //     path: '/businessSupervision',
    //     component: Layout,
    //     redirect: '/businessSupervision',
    //     meta: { title: "业务办理监督", icon: 'star', affix: true },
    //     children: [{
    //         path: '/businessSupervision/index',
    //         component: () =>
    //             import('@/views/businessSupervision/index'),
    //         name: 'businessSupervisionIndex',
    //         meta: { title: "业务办理监督" }
    //     },]
    // }, {
    //     path: '/lawsRegulations',
    //     component: Layout,
    //     redirect: '/lawsRegulations',
    //     meta: { title: "法律法规管理", icon: 'star', affix: true },
    //     children: [{
    //         path: '/lawsRegulations/law',
    //         component: () =>
    //             import('@/views/lawsRegulations/law'),
    //         name: 'lawsRegulationsLaw',
    //         meta: { title: "法律法规" }
    //     }, {
    //         path: '/lawsRegulations/policy',
    //         component: () =>
    //             import('@/views/lawsRegulations/policy'),
    //         name: 'lawsRegulationsPolicy',
    //         meta: { title: "政策法规" }
    //     }, {
    //         path: '/lawsRegulations/notice',
    //         component: () =>
    //             import('@/views/lawsRegulations/notice'),
    //         name: 'lawsRegulationsNotice',
    //         meta: { title: "通知公告" }
    //     },]
    // },

    // {
    //     path: '/PatrolTaskManagement',
    //     component: Layout,
    //     redirect: '/PatrolTaskManagement',
    //     meta: { title: "履职巡检监督", icon: 'star', affix: true },
    //     children: [{
    //         path: '/PatrolTaskManagement/matterItems',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/matterItems'),
    //         name: 'PatrolTaskManagementMatterItems',
    //         meta: { title: "履职监管清单" }
    //     }, {
    //         path: '/PatrolTaskManagement/matters',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/matters'),
    //         name: 'PatrolTaskManagementMatters',
    //         meta: { title: "巡查事项管理" }
    //     }, {
    //         path: '/PatrolTaskManagement/doubleRandomMatters',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/doubleRandomMatters'),
    //         name: 'PatrolTaskManagementDoubleRandomMatters',
    //         meta: { title: "双随机巡检管理" }
    //     }, {
    //         path: '/PatrolTaskManagement/specialMatters',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/specialMatters'),
    //         name: 'PatrolTaskManagementSpecialMatters',
    //         meta: { title: "专项巡检管理" }
    //     }, {
    //         path: '/PatrolTaskManagement/inspectionRecord',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/inspectionRecord'),
    //         name: 'PatrolTaskManagementInspectionRecord',
    //         meta: { title: "巡检记录管理" }
    //     }, {
    //         path: '/PatrolTaskManagement/inspectionItemRecord',
    //         component: () =>
    //             import('@/views/PatrolTaskManagement/inspectionItemRecord'),
    //         name: 'PatrolTaskManagementInspectionItemRecord',
    //         meta: { title: "巡检事项记录" }
    //     },]
    // },
    // {
    //     path: '/planning',
    //     component: Layout1,
    //     redirect: '/index',
    //     children: [{
    //         path: '/planning/index',
    //         component: () =>
    //             import ('@/views/planning/index'),
    //         name: 'Planning',
    //         meta: { title: "派单规则管理", icon: 'star', affix: true }
    //     }, ]
    // },
    // {
    //     path: '/performanceSupport',
    //     component: Layout,
    //     redirect: '/performanceSupport',
    //     meta: { title: "履职支撑管理", icon: 'star', affix: true },
    //     children: [{
    //         path: '/performanceSupport/supervise',
    //         component: () =>
    //             import('@/views/performanceSupport/supervise'),
    //         name: 'supervise',
    //         meta: { title: "工商登记信息" }
    //     },
    //     {
    //         path: '/performanceSupport/license',
    //         component: () =>
    //             import('@/views/performanceSupport/license'),
    //         name: 'license',
    //         meta: { title: "行政许可信息" }
    //     }, {
    //         path: '/performanceSupport/illegalInfo',
    //         component: () =>
    //             import('@/views/performanceSupport/illegalInfo'),
    //         name: 'illegalInfo',
    //         meta: { title: "行政处罚信息" }
    //     },
    //     ]
    // },

    // {
    //     path: '/listing',
    //     component: Layout,
    //     redirect: '/listing',
    //     meta: { title: "一张清单体系", icon: 'star', affix: true },
    //     children: [{
    //         path: '/listing/departments',
    //         component: () =>
    //             import('@/views/listing/departments'),
    //         name: 'listingareas',
    //         meta: { title: "部门三定清单" }
    //     },{
    //         path: '/listing/areas',
    //         component: () =>
    //             import('@/views/listing/areas'),
    //         name: 'listingareas',
    //         meta: { title: "镇街三张清单" }
    //     }, {
    //         path: '/listing/High',
    //         component: () =>
    //             import('@/views/listing/High'),
    //         name: 'listingHigh',
    //         meta: { title: "行政监管清单" }
    //     }, {
    //         path: '/listing/market',
    //         component: () =>
    //             import('@/views/listing/market'),
    //         name: 'listingmarket',
    //         meta: { title: "领域监管清单" }
    //     }, {
    //         path: '/listing/grid',
    //         component: () =>
    //             import('@/views/listing/grid'),
    //         name: 'listinggrid',
    //         meta: { title: "网格巡查清单" }
    //     },{
    //         path: '/listing/inspectionZhenjie',
    //         component: () =>
    //             import('@/views/listing/inspectionZhenjie'),
    //         name: 'inspectionZhenjie',
    //         meta: { title: "综合执法缜街巡查清单" }
    //     }, ]
    // },

    // {
    //     path: '/work',
    //     component: Layout,
    //     redirect: '/index',
    //     children: [{
    //         path: '/work/index',
    //         component: () =>
    //             import('@/views/workOrder/index'),
    //         name: 'WorkOrder',
    //         meta: { title: "工单管理", icon: 'star', affix: true }
    //     },]
    // },

    // {
    //     path: '/StatisticalAnalysis',
    //     component: Layout,
    //     redirect: '/StatisticalAnalysis',
    //     meta: { title: "统计分析", icon: 'star', affix: true },
    //     children: [{
    //         path: '/StatisticalAnalysis/regulatoryObject',
    //         component: () =>
    //             import('@/views/StatisticalAnalysis/regulatoryObject'),
    //         name: 'StatisticalAnalysisRegulatoryObject',
    //         meta: { title: "监管对象统计" }
    //     },
    //     {
    //         path: '/StatisticalAnalysis/agencyInspection',
    //         component: () =>
    //             import('@/views/StatisticalAnalysis/agencyInspection'),
    //         name: 'StatisticalAnalysisAgencyInspection',
    //         meta: { title: "机构巡检统计" }
    //     },
    //     {
    //         path: '/StatisticalAnalysis/inspectionPersonnel',
    //         component: () =>
    //             import('@/views/StatisticalAnalysis/inspectionPersonnel'),
    //         name: 'StatisticalAnalysisInspectionPersonnel',
    //         meta: { title: "人员巡检统计" }
    //     },
    //     {
    //         path: '/StatisticalAnalysis/accordingIndustry',
    //         component: () =>
    //             import('@/views/StatisticalAnalysis/accordingIndustry'),
    //         name: 'StatisticalAnalysisAccordingIndustry',
    //         meta: { title: "按行业统计" }
    //     },
    //     {
    //         path: '/StatisticalAnalysis/checkType',
    //         component: () =>
    //             import('@/views/StatisticalAnalysis/checkType'),
    //         name: 'StatisticalAnalysisCheckType',
    //         meta: { title: "按检查类型统计" }
    //     },

            // {
            //     path: '/StatisticalAnalysis/accordingMatters',
            //     component: () =>
            //         import ('@/views/StatisticalAnalysis/accordingMatters'),
            //     name: 'StatisticalAnalysisAccordingMatters',
            //     meta: { title: "按事项统计" }
            // },
    //     ]
    // },
    { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
var constantRoutes2 = [
    {
        path: '/redirect',
        component: Layout1,
        hidden: true,
        children: [{
            path: '/redirect/:path(.*)',
            component: () =>
                import('@/views/redirect/index')
        }]
    },
    {
        path: '/login',
        component: () =>
            import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () =>
            import('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () =>
            import('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () =>
            import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/',
        component: Layout1,
        redirect: '/dashboard',
        hidden: true,
        children: [{
            path: '/dashboard',
            component: () =>
                import('@/views/backlog/index'),
            name: 'Dashboard',
            meta: { title: "我的待办", icon: 'star', affix: true }
        }, 
        {
            path: '/caseDetail',
            component: () =>
                import('@/views/caseDetail/caseDetail'),
            name: 'CaseDetail',
            hidden: true,
            meta: { title: '案件详情', tools: false }
        }, 
        {
            path: '/caseDetail2',
            component: () =>
                import('@/views/caseDetail/caseDetail2'),
            name: 'CaseDetail2',
            hidden: true,
            meta: { title: '案件详情', tools: false }
        },
        {
            path: '/caseDetail3',
            component: () =>
                import('@/views/caseDetail/caseDetail3'),
            name: 'CaseDetail3',
            hidden: true,
            meta: { title: '案件详情', tools: false }
        },
    ]
    },
    // {
    //     path: '/waitDispatchOrder',
    //     component: Layout1,
    //     hidden: true,
    //     redirect: '/waitDispatchOrder',
    //     meta: { title: "派遣事项", icon: 'star', affix: true },
    //     children: [{
    //         path: '/waitDispatchOrder/index',
    //         component: () =>
    //             import('@/views/waitDispatchOrder/index'),
    //         name: 'waitDispatchOrder',
    //         meta: { title: "待派遣工单" }
    //     },
    //     {
    //         path: '/sureDispatchOrder/index',
    //         component: () =>
    //             import('@/views/sureDispatchOrder/index'),
    //         name: 'sureDispatchOrder',
    //         meta: { title: "已派遣工单" }
    //     },
    //     ]
    // },
    // {
    //     path: '/caseDeal',
    //     component: Layout1,
    //     hidden: true,
    //     redirect: '/caseDeal',
    //     meta: { title: "案件处理", icon: 'star', affix: true },
    //     children: [
    //         path: '/caseDeal/dispatch',
    //         component: () =>
    //             import('@/views/casedeal/dispatch2'),
    //         name: 'CaseDealDispatch',
    //         meta: { title: "受理登记" },
    //     },
        // {
        //     path: '/BackOffList',
        //     component: () =>
        //         import('@/views/BackOffList/index'),
        //     name: 'BackOffList',
        //     meta: { title: "回退列表" }
        // },
         // {
        //     path: '/caseList',
        //     component: () =>
        //         import('@/views/caseList/index'),
        //     name: 'caseList',
        //     meta: { title: "案件列表" }
        // },
        // {
        //     path: '/delayList',
        //     component: () =>
        //         import('@/views/delayList/index'),
        //     name: 'delayList',
        //     meta: { title: "延期列表" }
        // },
    //     {
    //         path: '/handled/index',
    //         component: () =>
    //             import('@/views/handled/index'),
    //         name: 'index',
    //         meta: { title: "我的已办" }
    //     },
    //     {
    //         path: '/filesQuery/index',
    //         component: () =>
    //             import('@/views/filesQuery/index'),
    //         name: 'index',
    //         meta: { title: "案件查询" }
    //     },
    //     {
    //         path: '/backAudit',
    //         component: () =>
    //             import('@/views/backAudit/index'),
    //         name: 'index',
    //         meta: { title: "回退审核" }
    //     },
    //     {
    //         path: '/deferredAudit',
    //         component: () =>
    //             import('@/views/deferredAudit/index'),
    //         name: 'index',
    //         meta: { title: "延期审核" }
    //     },
    // {
    //     path: '/BackOffList',
    //     component: () =>
    //         import('@/views/BackOffList/index'),
    //     name: 'BackOffList',
    //     meta: { title: "回退列表", icon: 'star', affix: true }
    // },
    // {
    //     path: '/delayList',
    //     component: () =>
    //         import('@/views/delayList/index'),
    //     name: 'BackOffList',
    //     meta: { title: "延期列表", icon: 'star', affix: true }
    // },

    //     ]
    // },

    // {
    //     path: '/statistical',
    //     component: Layout1,
    //     hidden: true,
    //     redirect: '/statistical',
    //     meta: { title: "统计分析", icon: 'star', affix: true },
    //     children: [{
    //         path: '/statistical/Acceptor',
    //         component: () =>
    //             import('@/views/statistical/Acceptor'),
    //         name: 'statisticalAcceptor',
    //         meta: { title: "受理员统计" }
    //     }, {
    //         path: '/statistical/departments',
    //         component: () =>
    //             import('@/views/statistical/departments'),
    //         name: 'statisticaldepartments',
    //         meta: { title: "职能部门统计" }
    //     }, {
    //         path: '/statistical/satisfaction',
    //         component: () =>
    //             import('@/views/statistical/satisfaction'),
    //         name: 'statisticalsatisfaction',
    //         meta: { title: "部门满意度统计" }
    //     }, {
    //         path: '/statistical/area',
    //         component: () =>
    //             import('@/views/statistical/area'),
    //         name: 'statisticalarea',
    //         meta: { title: "区域统计" }
    //     }, {
    //         path: '/statistical/classification',
    //         component: () =>
    //             import('@/views/statistical/classification'),
    //         name: 'statisticalclassification',
    //         meta: { title: "分类统计" }
    //     }, {
    //         path: '/statistical/source',
    //         component: () =>
    //             import('@/views/statistical/source'),
    //         name: 'statisticalsource',
    //         meta: { title: "来源统计" }
    //     },]
    // },

    // {
    //     path: '/BackOffList',
    //     component: Layout1,
    //     hidden: true,
    //     redirect: '/BackOffList',
    //     children: [{
    //         path: '/BackOffList',
    //         component: () =>
    //             import('@/views/BackOffList/index'),
    //         name: 'BackOffList',
    //         meta: { title: "回退列表", icon: 'star', affix: true }
    //     },]
    // },

    // {
    //     path: '/awitReturnVisit',
    //     component: Layout1,
    //     redirect: '/index',
    //     children: [{
    //         path: '/awitReturnVisit/index',
    //         component: () =>
    //             import('@/views/awitReturnVisit/index'),
    //         name: 'awitReturnVisit',
    //         meta: { title: "待回访列表", icon: 'star', affix: true }
    //     },]
    // },

    // {
    //     path: '/VoiceAgent',
    //     component: Layout1,
    //     redirect: '/index',
    //     hidden: true,
    //     children: [{
    //         path: '/VoiceAgent/index',
    //         component: () =>
    //             import('@/views/VoiceAgent/index'),
    //         name: 'VoiceAgent',
    //         meta: { title: "语音座席", icon: 'star', affix: true }
    //     },]
    // }, 

//  {
//         path: '/opinionManagement',
//         component: Layout1,
//         redirect: '/index',
//           meta: { title: "常用意见管理", icon: 'star', affix: true },
//         children: [{
//             path: '/applicableRole',
//             component: () =>
//                 import('@/views/opinionManagement/index'),
//             name: 'opinionManagement',
//             meta: { title: "常用意见管理" }
//         },
//     {
//                 path: '/applicableDepartment',
//                 component: () =>
//                     import('@/views/opinionManagement/applicableDepartment'),
//                 name: 'VoiceAgent',
//                 meta: { title: "适用部门" }
//             },
//          {
//                 path: '/applicableFunction',
//                 component: () =>
//                     import('@/views/opinionManagement/applicableFunction'),
//                 name: 'VoiceAgent',
//                 meta: { title: "适用功能" }
//             },
//          {
//                 path: '/opinionContent',
//                 component: () =>
//                     import('@/views/opinionManagement/opinionContent'),
//                 name: 'VoiceAgent',
//                 meta: { title: "意见内容" }
//             },
//     ]
//     },

    // { path: '*', redirect: '/404', hidden: true }
]

var constantRoutes3 = [{
    path: '/demo',
    component: Layout,
    meta: { title: "DEMO", icon: 'example' },
    redirect: '/listDemo',
    children: [{
        path: '/demo/listDemo',
        component: () =>
            import('@/views/demo/listDemo'),
        name: 'ListDemo',
        meta: { title: '列表', }
    }, {
        path: '/demo/cardDemo',
        component: () =>
            import('@/views/demo/cardDemo'),
        name: 'CardDemo',
        meta: { title: '卡片', }
    }, {
        path: '/demo/detailDemo',
        component: () =>
            import('@/views/demo/detailDemo'),
        name: 'detailDemo',
        meta: { title: '详情', tools: true }
    }, {
        path: '/demo/dialog',
        component: () =>
            import('@/views/demo/treeTableDemo'),
        name: 'TreeTableDemo',
        meta: { title: '弹出框' }
    }]
},
{
    path: '/redirect',
    component: Layout1,
    hidden: true,
    children: [{
        path: '/redirect/:path(.*)',
        component: () =>
            import('@/views/redirect/index')
    }]
},
{
    path: '/login',
    component: () =>
        import('@/views/login/index'),
    hidden: true
},
{
    path: '/auth-redirect',
    component: () =>
        import('@/views/login/auth-redirect'),
    hidden: true
},
{
    path: '/404',
    component: () =>
        import('@/views/error-page/404'),
    hidden: true
},
{
    path: '/401',
    component: () =>
        import('@/views/error-page/401'),
    hidden: true
},
{
    path: '/',
    component: Layout1,
    redirect: '/dashboard',
    children: [{
        path: '/dashboard',
        component: () =>
            import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: "主页", icon: 'star', affix: true }
    }, {
        path: '/caseDetail',
        component: () =>
            import('@/views/caseDetail/caseDetail'),
        name: 'CaseDetail',
        hidden: true,
        meta: { title: '案件详情', tools: false }
    }]
},
{
    path: '/caseDeal',
    component: Layout1,
    redirect: '/caseDeal',
    meta: { title: "案件处理", icon: 'star', affix: true },
    children: [{
        path: '/caseDeal/dispatch',
        component: () =>
            import('@/views/casedeal/dispatch2'),
        name: 'CaseDealDispatch',
        meta: { title: "受理登记" }
    },
    {
        path: '/caseDeal/deal',
        component: () =>
            import('@/views/dashboard/index'),
        name: 'CaseDeal',
        meta: { title: "案件处理" }
    },
    {
        path: '/caseDeal/list',
        component: () =>
            import('@/views/dashboard/list'),
        name: 'CaseDealList',
        meta: { title: "案件列表" }
    },
    {
        path: '/caseHading',
        component: () =>
            import('@/views/caseHading/index'),
        name: 'caseHading',
        meta: { title: "接件分发" }
    },
    ]
},

{
    path: '/planning',
    component: Layout1,
    redirect: '/index',
    children: [{
        path: '/planning/index',
        component: () =>
            import('@/views/planning/index'),
        name: 'Planning',
        meta: { title: "派单规则管理", icon: 'star', affix: true }
    },]
},

{ path: '*', redirect: '/404', hidden: true }
]


function getUrlKey(val) {
    return decodeURIComponent((new RegExp('[?|&]' + val + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}

export var constantRoutes = []
// console.log(getUrlKey('app'))
if ( getUrlKey('app') == 1) {
    constantRoutes = constantRoutes2
} else if ( getUrlKey('app') == 2) {
    constantRoutes = constantRoutes1
} else {
    constantRoutes = constantRoutes2
}

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes,
    // routes: asyncRoutes,

})

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router